package com.dingding.manager.modules.system.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dingding.manager.common.beans.SysProvince;
import com.dingding.manager.modules.dirver.dto.RespResult;
import com.dingding.manager.modules.system.dto.proandcity.CityDTO;
import com.dingding.manager.modules.system.service.ProvinceAndCityService;

/**
 * 
 * @Description: 省市级联查询表现层
 * @author haoxiaojun
 * @date 2016年12月3日 上午10:43:00
 * @since V 2.5.7
 */
@Controller
@RequestMapping("/proandcity/v1")
public class ProvinceAndCityController {

	// 日志
	Logger log = Logger.getLogger(ProvinceAndCityController.class);

	// 省市级联查询服务
	@Resource(name = "provinceAndCityService")
	private ProvinceAndCityService provinceAndCityService;

	/**
	 * 
	 * @Description: 获取所有省份信息
	 * @author haoxiaojun
	 * @return void
	 * @date 2016年12月3日 上午10:53:36
	 * @since V 2.5.7
	 */
	@RequestMapping(value = "/pro", method = { RequestMethod.POST })
	@ResponseBody
	public RespResult<SysProvince> getProvince(HttpServletRequest request, HttpServletResponse response) {
		
		List<SysProvince> proviceList = provinceAndCityService.getProvince();
		RespResult<SysProvince> results = new RespResult<>();
		results.setAaData(proviceList);
		return results;

	}

	
	/**
	 * 
	 * @Description: 根据省份ID获取当前省份下的所有城市
	 * @author haoxiaojun
	 * @return void
	 * @date 2016年12月3日 上午11:51:03
	 * @since V 2.5.7
	 */
	@RequestMapping(value = "/city", method = { RequestMethod.POST })
	@ResponseBody
	public RespResult<CityDTO> getAllCity(Integer proviceId, HttpServletRequest request,
			HttpServletResponse response) {

		List<CityDTO> cityList = provinceAndCityService.getCity(proviceId);
		RespResult<CityDTO> results = new RespResult<>();
		results.setAaData(cityList);
		return results;

	}
	
	
}
